package com.hoshiicloud.common.validate.annotations.impl;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.hoshiicloud.common.validate.annotations.IsNumber;
import org.apache.commons.lang3.StringUtils;

/**
 * 数字验证注解实现类
 *
 * @author : yangcheng
 * @date : 2019/5/13 15:49
 * @mail : maiboyc@163.com
 **/
public class IsNumberValidatorImpl implements ConstraintValidator<IsNumber, String> {

    @Override
    public void initialize(IsNumber constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(StringUtils.isBlank(value)){
            return false;
        }
        String regex = "^[0-9]*$";
        if (value.matches(regex)) {
            return true;
        } else {
            return false;
        }
    }

}